package com.axjy.controller;

import com.axjy.controller.dto.UserDto;
import com.axjy.pojo.User;
import com.axjy.service.UserService;
import com.axjy.util.Log;
import com.axjy.util.Pager;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by asus on 2017/9/25.
 */
@RestController
@RequestMapping("/sys/user")
public class UserHandler {

    @Resource
    private UserService userService;

    @RequestMapping("/search")
    public Pager search(Integer offset,Integer limit, UserDto dto){
        return userService.searchByDyna(offset,limit,dto);
    }

    @RequestMapping("/grant")
    public String grant(Integer id,Integer roleId){
        String msg="用户授权成功";
        try{
            userService.grant(id,roleId);
        }catch(RuntimeException ex){
            msg="用户授权失败";
            Log.logger.error(msg,ex);
        }
        return msg;
    }

    @RequestMapping("/searchByRid")
    public List<User> searchByRid(Integer rid){
        return userService.searchByRole(rid);
    }





}
